package com.coding.kan_yi_dao.service.impl;

import com.coding.kan_yi_dao.common.Result;
import com.coding.kan_yi_dao.entity.GoodsNew;
import com.coding.kan_yi_dao.mapper.GoodsNewMapper;
import com.coding.kan_yi_dao.service.IGoodsNewService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 砍一刀，不买就砍你一刀
 * @since 2023-09-20
 */
@Service
public class GoodsNewServiceImpl extends ServiceImpl<GoodsNewMapper, GoodsNew> implements IGoodsNewService {
    @Resource
    GoodsNewMapper goodsNewMapper;
    //查询
    @Override
    public Result go_select_all() {
        List<GoodsNew> a = query().eq("goods_delete",1).list();
        return Result.ok(a);
    }
//修改
    @Override
    public Result go_update(GoodsNew goodsNews) {
        return Result.ok(baseMapper.updateById(goodsNews));
    }

    //假删除
    @Override
    public Result go_noupdate(List<Integer> ids) {
        List<GoodsNew> goodsNewss = new ArrayList<>();
        for (int i = 0; i < ids.size(); i++) {
            GoodsNew goodsNew = new GoodsNew();
            goodsNew.setGoodsNewId(ids.get(i));
            goodsNew.setGoodsDelete(0);
            goodsNewss.add(goodsNew);
        }
        /*System.out.println(goodsNewss);return Result.ok(this.update().setSql("goods_delete=0").in("goods_new_id",goodsNewss).update());*/
        return Result.ok(updateBatchById(goodsNewss));
    }

    //添加
    @Override
    public Result go_insert(GoodsNew goodsNew) {
        return Result.ok(baseMapper.insert(goodsNew));
    }

    //多表查询
    @Override
    public  Result go_select_goods(GoodsNew goodsNew){
        System.out.println(goodsNew.getGoodsNewId());
        Integer b =goodsNew.getGoodsNewId();
        List<GoodsNew> a = goodsNewMapper.go_select_goods(b);
        return Result.ok(a);
    }

}
